<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
Netty WebSocket 时间服务器
</head>
<br>
<script type="text/javascript">
var socket;
if(!window.WebSocket) {
	window.WebSocket = window.MozWebSocket;
}
if(window.WebSocket) {
	socket = new WebSocket("ws://127.0.0.1:8080/websocket");
	socket.onmessage = function(event) {
		var text = document.getElementById('responseText');
		text.value = "";
		text.value = event.data;
	}
	socket.onopen = function(event) {
		var text = document.getElementById('responseText');
		text.value = "连接WebSocket服务正常，浏览器支持WebSocket!";
	}
	socket.onclose = function(event) {
		var text = document.getElementById('responseText');
		text.value = "";
		text.value = "WebSocket 关闭!";
	}
} else {
	alert("抱歉，您的浏览器不支持WebSocket协议!");
}

function send(msg) {
	if(!window.WebSocket) {
		return ;
	}
	if(socket.readyState==WebSocket.OPEN) {
		socket.send(msg);
	} else {
		alert("WebSocket服务还没有连接！");
	}
}
</script>
<body>
	<br>
	<form onsubmit="return false;">
		<input type="text" name="message" value="Netty 权威指南" /> <br> <br>
		<input type="button" value="发送"
			onclick="send(this.form.message.value)" />
		<hr color="blue" />
		<h3>服务端应答消息</h3>
		<textarea id="responseText" style="width: 500px; height: 300px;"></textarea>
	</form>
</body>
</html>